/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package PaqueteServelt;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import cl.tienda.modelo.*;
/**
 *
 * @author 17125223-7
 */
public class ServletCAgrCarrito2 extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            
            int indice=Integer.parseInt(request.getParameter("indice"));
            Vector <Producto> vprod=(Vector<Producto>)request.getSession().getAttribute("productos");
            
            int cod   = vprod.get(indice).getCodigo();
            String nom= vprod.get(indice).getNombreproducto();
            int stock= vprod.get(indice).getStock();
            
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletCAgrCarrito2</title>");            
            out.println("</head>");
            out.println("<body>");
            
            out.println("<form name='form1' action='ServletCAgrCarrito3' method='post'>");
            out.println("<table>");
            out.println("<tr>");
            out.println("<td>Codigo</td><td><input type='text' readonly value='"+cod+"'></td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Producto</td><td>"+nom+"</td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Stock</td><td>"+stock+"</td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Cant. a pedir</td><td>"
                 + "<input type='text' name='cantidad' value='1' size='4'>" 
                 + "</td>");
            out.println("</tr>");
            
            out.println("<tr>");
            out.println("<td></td><td>"
                 + "  <input type='submit' name='Enviar'>" 
                 + "</td>");
            out.println("</tr>");
            out.println("</table>");
            out.println("</form>");
            
            
            out.println("</body>");
            out.println("</html>");
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
